<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
  <th:block th:include="include :: header('AI智能识别数据集列表')" />

  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>数据集名称：</label>
                                <input type="text" name="collectionName"/>
                            </li>
                            <li>
                                模型名称：
                                <select name="modelId">
                                    <option value="" placeholder="--请选择模型名称--"  >--请选择模型名称--</option>
                                    <option value="1">人和安全帽</option>
                                    <option value="2">人员装备</option>
                                    <option value="3">主煤流检测</option>
                                    <option value="4">人和车检测</option>
                                    <option value="5">煤流量</option>
                                </select>
                            </li>
                            <li>
                                模型类别：<select >
                                <option value="" placeholder="--请选择模型类别--"  >--请选择模型类别--</option>
                                <option value="default"  >目标检测</option>
                                <option value="arrows" >图像分类</option>
                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                            <div>
                                <span>2024年3月11日&nbsp;&nbsp;18:48:15&nbsp;&nbsp;星期一&nbsp;&nbsp;</span>
                            </div>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="AI:CollectionService:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="AI:CollectionService:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="AI:CollectionService:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('AI:collectionService:edit')}]];
        var uploadFlag = [[${@permission.hasPermi('AI:collectionService:upload')}]];
        var removeFlag = [[${@permission.hasPermi('AI:collectionService:remove')}]];
        var prefix = ctx + "AI/collectionService";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "AI智能识别数据集",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'collectionId',
                        title: '数据集ID',
                        visible: false
                    },
                    {
                        field: 'modelName',
                        title: '模型名称'
                    },
                    {
                        field: 'modelKind',
                        title: '模型类别',
                    },
                    {
                        field: 'collectionName',
                        title: '数据集名称'
                    },
                    {
                        field: 'collectionType',
                        title: '数据集类型'
                    },
                    {
                        field: 'collectionImgNum',
                        title: '数据集图片数量'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.collectionId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.collectionId + '\')"><i class="fa fa-remove"></i>删除</a>');
                           actions.push('<button class="btn btn-success btn-xs " href="javascript:void(0)" onclick="startUpload(' + row.modelId + ')"><i class="fa fa-edit"></i>上传图片</button> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.collectionId + '\')"><i class="fa fa-edit"></i>标注</a> ');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        });



      function myUploadFile(data) {
          console.log("发送秦秋开始")

          axios({
              method: "post",
              headers: {
                  "Content-Type": "multipart/form-data"
              },
              crossDomain: true,
              data,
              url: '/AI/checkService/upload',
          }).then((res) => {
              console.log("上传返回=res{}", res);
          });
          console.log("发送秦秋借宿")
    };

    // 开始上传
    function startUpload(modelId) {

      // 创建一个input元素
      let input = document.createElement("input");
      // 类型设为文件
      input.type = "file";
      // 选取图片点击确定的时候触发
      input.onchange = () => {
        // 这里我只是上传单个文件，所以选取第一个，多个的话可以在外面搞个循环
        let file = input.files[0];
        // 获取文件名中.最后一次出现的索引
        let index = file.name.lastIndexOf(".");
        // 获取后缀名
        let suffix = file.name.substring(index + 1);

        // if (this.picFormat.indexOf(suffix.toLowerCase()) == -1) {
        // 	this.$message.warning("只允许上传图片");
        // } else {
        // 转为二进制流，开始上传
        let blob = new FormData();
        // append的第一个参数‘file’，对应后端接收的参数名，一致即可
        blob.append("file", file);
        blob.append("modelId", modelId)
        blob.append("index", 1)
        // 调用上传接口，把blob传过去
        myUploadFile(blob);
        // }
      };
      // 模拟点击
      input.click();
      // 移除该元素
      input.remove();
    };
    </script>
</body>

</html>